package cn.lijiancn01.demo.framework.config.mybatis;

import cn.lijiancn01.demo.framework.model.PageResult;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.query.QueryWrapper;

import static com.mybatisflex.core.query.QueryMethods.column;

/**
 * BaseMapper 扩展
 *
 * @param <T>
 */
public interface BaseMapperX<T> extends BaseMapper<T> {
    QueryColumn CODE = column("code");

    default T selectOneByCode(String code) {
        QueryWrapper query = QueryWrapper.create().where(
                CODE.eq(code)
        );
        return selectOneByQuery(query);
    }

    default <VO> PageResult<VO> findByCondition(Number pageNumber, Number pageSize, QueryWrapper queryWrapper, Class<VO> voClz) {
        Page<T> pageResult = paginate(pageNumber, pageSize, queryWrapper);
        return PageResult.of(pageResult, voClz);
    }
}
